<?php

namespace App\Http\Controllers\TeacherApi\User;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Users;
use Auth;

class LoginController extends Controller
{
	//单独为api写登录接口
	public function login(Request $request,Users $users){
		$username = $request->username;
		$password = $request->password;
		$this->data['msg'] = '账户或密码不正确！';
		if(Auth::attempt(['username' => $username, 'password' => $password])){
			$userInfo = $users->where('username',$username)->first();
			$this->data['msg'] = '登录成功！';
			$this->data['code'] = 1;
			$this->data['data'] = $userInfo;
		}

		return $this->data;
	}

	// 注册接口
	public function reg(Request $request,Users $users){
		
		return $this->data;
	}

	// 修改密码
	public function edit_password(Request $request,Users $users){
		$password = bcrypt($request->password);
		$id = $request->id;
		$rs = $users->where('id',$id)->update(['password'=>$password]);
		if($rs){
			$this->data['msg'] = '修改成功！';
			$this->data['code'] = 1;

		}
		$this->data['data'] = $request->all();
		return $this->data;
	}
   

}